import hljs from 'highlight.js';
import { IconContext } from 'react-icons';
import { FcFile, FcFolder } from 'react-icons/fc';
import ReactMarkdown from 'react-markdown';
import gfm from 'remark-gfm';
function isNotMaster(pathArray) {
if (pathArray.length > 2) {
if (pathArray[2] !== 'master') {
return true;
} else return false;
} else return false;
}
function getSubArray(pathArray, depth) {
if (depth === 0) {
if (isNotMaster(pathArray)) {
return pathArray.slice(0, 1).concat('tree', pathArray[2]);
} else return pathArray.slice(0, 1);
} else return pathArray.slice(0, 1).concat('tree', pathArray.slice(2, depth + 1));
}
async function getServerSideProps(context) {
const res = await fetch('http://localhost:3000/api' + context.resolvedUrl);
const data = await res.json();
return { props: { data } };
}
function RepositoryListing(props) {
return (
{props.repositories.map((repo) => (
))}
);
}
function MidSection(props) {
return (
{props.children}
);
}
function MainContentContainer(props) {
return (
{props.children}
);
}
function BreadCrumbTrail(props) {
const pathArray = props.pathArray;
const recursion = (acc) => {
if (acc.length === pathArray.length - 1) {
return acc;
} else {
const subArray = getSubArray(pathArray, acc.length);
const breadCrumb = {
name: pathArray[acc.length],
href: '/' + subArray.join('/'),
};
const newAcc = acc.concat([breadCrumb]);
return recursion(newAcc);
}
};
if (pathArray.length < 4) {
return null;
}
const breadCrumbs = recursion([]);
// remove repoRequest and commit
breadCrumbs.splice(1, 2);
return (
{breadCrumbs.map((breadCrumb) => (
/ {breadCrumb.name}
))}
/ {pathArray[pathArray.length - 1]}
);
}
function DirectoryListing(props) {
const resultPath = props.resultPath;
const makeURL = (repoRequest, item) => {
const parentTail = resultPath.length > 2 ? resultPath.slice(2) : ['master'];
const parentPath = resultPath.slice(0, 1).concat(repoRequest, parentTail);
const url = '/' + parentPath.join('/') + '/' + item;
return url;
}
return (
{props.resultContent.trees.map((item) => (
-
{item}
))}
{props.resultContent.blobs.map((item) => (
-
{item}
))}
);
}
function CommitListing(props) {
const subArray = props.resultContent.slice(1);
return (
);
}
function LineNos(props) {
const count = props.textBlob.split('\n').length;
const lineNos = [...Array(count).keys()].map((x) => x + 1).join('\n');
return (
{lineNos}
);
}
function CodeBlock(props) {
const highlightedHTML = hljs.highlightAuto(props.textBlob).value;
return (
);
}
function TextDisplayGrid(props) {
return (
);
}
function PageSubstance({ data }) {
switch (data.resultType) {
case 'home':
return ;
break;
case 'rootDirectory':
const imageURITransformer = (uri) => '/' + data.resultPath[0] + '/raw/master/' + uri;
return (
{data.resultContent.readmeExists &&
}
{data.resultContent.readmeExists &&
}
);
break;
case 'nonRootDirectory':
return (
);
break;
case 'textBlob':
return (
);
break;
case 'binaryBlob':
return (
Binary content cannot be displayed.
);
break;
case 'commits':
return (
);
break;
case 'error':
return (
Error:
{data.resultContent}
);
break;
default:
return (
Error:
Backend error: result type not recognised.
);
}
}
function Main({ data }) {
return (
);
}
export { getServerSideProps };
export default Main;